package edu.sdjzu.exam.mapper;




import edu.sdjzu.exam.domain.question.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionMapper {

    @Insert("INSERT INTO Questions (content, question_type, reference_answer, subject, difficulty, created_by, course_id) " +
            "VALUES (#{content}, #{questionType}, #{referenceAnswer}, #{subject}, #{difficulty}, #{createdBy}, #{courseId})")
    @Options(useGeneratedKeys = true, keyProperty = "questionId")
    void insertQuestion(Question question);

    @Select("SELECT * FROM Questions WHERE question_id = #{questionId}")
    Question selectQuestionById(Long questionId);

    @Update("UPDATE Questions SET content = #{content}, question_type = #{questionType}, " +
            "reference_answer = #{referenceAnswer}, subject = #{subject}, difficulty = #{difficulty} " +
            "WHERE question_id = #{questionId}")
    void updateQuestion(Question question);

    @Delete("DELETE FROM Questions WHERE question_id = #{questionId}")
    void deleteQuestion(Long questionId);

    @Select("SELECT * FROM Questions WHERE created_by = #{createdBy}")
    List<Question> selectQuestionsByCreator(Long createdBy);
    
    // 根据课程ID查询题目
    @Select("SELECT * FROM Questions WHERE course_id = #{courseId}")
    List<Question> selectQuestionsByCourse(Long courseId);
    
    // 根据课程ID和创建者查询题目
    @Select("SELECT * FROM Questions WHERE course_id = #{courseId} AND created_by = #{createdBy}")
    List<Question> selectQuestionsByCourseAndCreator(@Param("courseId") Long courseId, @Param("createdBy") Long createdBy);
}
